package cn.jhc.transport.fragment;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.json.JSONException;

import java.io.IOException;

import cn.jhc.transport.R;
import cn.jhc.transport.service.TransportService;

public class CarsFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_cars,container,false);
    }

    private class GetCarSpeedTask extends AsyncTask<String,Void,Integer> {

        @Override
        protected Integer doInBackground(String... strings) {
            Integer carId = Integer.valueOf(strings[0]);
            int speed;
            try {
                speed = new TransportService().getCarSpeed(carId);
            } catch (IOException e) {
                return -1;
            } catch (JSONException e) {
                return -2;
            }
            return speed;
        }

        protected void onPostExecute(Integer speed) {

        }
    }
}
